home *** CD-ROM | disk | FTP | other *** search
/ Champak 122 / Vol 122.iso / games / sketchbo.swf / scripts / DefineSprite_260_mc_commando_swing / frame_1 / DoAction.as
Encoding:
Text File  |  2011-01-06  |  5.2 KB  |  274 lines

  1. attacking = false;
  2. speed = 0;
  3. walking = false;
  4. if(!init)
  5. {
  6.    orig_scale = _xscale;
  7.    hitarea._visible = 0;
  8.    walking = false;
  9.    parrying = false;
  10.    attacking = false;
  11.    jumping = false;
  12.    fall_distance = 0;
  13.    init = true;
  14.    side = "L";
  15.    lastdecision = 0;
  16.    deadcount = 0;
  17.    floor = 62;
  18.    walk_distance = 10;
  19.    reach = 35;
  20.    damage = 24;
  21.    total_ki = 10;
  22.    ki = total_ki;
  23.    ki_cost = 5;
  24.    pushfactor = 9;
  25.    total_hp = 10 + _root.level * 5;
  26.    hp = total_hp;
  27.    regen_rate = 0.1;
  28.    score = 1250;
  29.    _root.createPic("pic_commando",this);
  30. }
  31. this.onEnterFrame = function()
  32. {
  33.    if(!init)
  34.    {
  35.       return undefined;
  36.    }
  37.    if(dead)
  38.    {
  39.       deadcount++;
  40.       if(deadcount > 1000)
  41.       {
  42.          trace("unloading:" + this);
  43.          this.removeMovieClip();
  44.          unloadMovie(this);
  45.       }
  46.       gotoAndStop("die");
  47.       this._x -= _hitomi.speed;
  48.       return undefined;
  49.    }
  50.    lastdecision++;
  51.    onDie();
  52.    doCalcs();
  53.    var _loc3_ = fallback();
  54.    if(_loc3_ == undefined)
  55.    {
  56.       _loc3_ = 0;
  57.    }
  58.    var _loc4_ = _root.hitomi.speed;
  59.    checkHits();
  60.    decide();
  61.    this._x -= _loc4_;
  62.    this._x += _loc3_;
  63. };
  64. checkHits = function()
  65. {
  66.    if(this.hitarea.hitTest(_hitomi.hitarea))
  67.    {
  68.       onHit();
  69.    }
  70.    if(_root.hitomi.hitTest(_X + club._x * getDirection(),_Y + club._y,true))
  71.    {
  72.       _root.hitomi.recieveHit(this);
  73.    }
  74.    if(_root.hitomi.hitTest(_X + (club._x + 3) * getDirection(),_Y + club._y,true))
  75.    {
  76.       _root.hitomi.recieveHit(this);
  77.    }
  78.    if(_root.hitomi.hitTest(_X + (club._x - 3) * getDirection(),_Y + club._y,true))
  79.    {
  80.       _root.hitomi.recieveHit(this);
  81.    }
  82. };
  83. doCalcs = function()
  84. {
  85.    if(!(walking || attacking || jumping || parrying || turning || recieving))
  86.    {
  87.       ki += regen_rate;
  88.    }
  89.    if(ki > total_ki)
  90.    {
  91.       ki = total_ki;
  92.    }
  93.    if(hp > total_hp)
  94.    {
  95.       hp = total_hp;
  96.    }
  97.    if(ki < 0)
  98.    {
  99.       ki = 0;
  100.    }
  101.    if(hp < 1)
  102.    {
  103.       hp = 0;
  104.       die();
  105.    }
  106.    pic.bars.hp._xscale = Math.ceil(hp / total_hp * 100);
  107.    pic.bars.ki._xscale = Math.ceil(ki / total_ki * 100);
  108. };
  109. getDirection = function()
  110. {
  111.    if(orig_scale == _xscale)
  112.    {
  113.       return 1;
  114.    }
  115.    return -1;
  116. };
  117. bombHit = function(hit_by, dmg, pushf)
  118. {
  119.    hp -= dmg;
  120. };
  121. onHit = function()
  122. {
  123.    _root.hitcount = _root.hitcount + 1;
  124.    if(_root.hitcount > 1000)
  125.    {
  126.       _root.hitcount = 0;
  127.    }
  128.    hp -= _hitomi.damage;
  129.    _root._score += _hitomi.damage;
  130.    var _loc3_ = _root.attachMovie("mc_blood01","blood" + hitcount,6000 + hitcount);
  131.    _loc3_._rotation = random(360);
  132.    var _loc4_ = random(150) + 100;
  133.    _loc3_._xscale = _loc4_;
  134.    _loc3_._yscale = _loc4_;
  135.    if(_hitomi.side == "R")
  136.    {
  137.       _loc3_._x = _hitomi._x + _hitomi.hitarea._x;
  138.       _loc3_._y = _hitomi._y + _hitomi.hitarea._y;
  139.    }
  140.    else
  141.    {
  142.       _loc3_._x = _hitomi._x - _hitomi.hitarea._x;
  143.       _loc3_._y = _hitomi._y + _hitomi.hitarea._y;
  144.    }
  145.    fall_distance = _hitomi.pushback * 2;
  146.    fallback = function()
  147.    {
  148.       fall_distance--;
  149.       if(fall_distance < 1)
  150.       {
  151.          delete this.fallback;
  152.          fall_distance = 0;
  153.          return 0;
  154.       }
  155.       return _hitomi.getDirection() * (fall_distance / 2);
  156.    };
  157.    soundsList = ["loud_metal_hit","blow01","beat","cabasa","zddd1kick1","zddd1kick2","zddd1tamb"];
  158.    playSound(soundsList);
  159. };
  160. die = function()
  161. {
  162.    _root.removePic(pic);
  163.    dead = true;
  164.    walking = false;
  165.    slashing = false;
  166.    attacking = false;
  167.    speed = 0;
  168.    gotoAndStop("die");
  169.    play();
  170. };
  171. decide = function()
  172. {
  173.    if(dead)
  174.    {
  175.       return undefined;
  176.    }
  177.    if(!attacking || lastdecision > 75)
  178.    {
  179.       lastdecision = 0;
  180.       if(random(120) == 0)
  181.       {
  182.          if(random(2) == 0)
  183.          {
  184.             _X = _hitomi._x + reach + random(6);
  185.             _xscale = orig_scale;
  186.          }
  187.          else
  188.          {
  189.             _X = _hitomi._x - reach - random(6);
  190.             _xscale = - orig_scale;
  191.          }
  192.          attack();
  193.       }
  194.    }
  195. };
  196. attack = function()
  197. {
  198.    if(!attacking)
  199.    {
  200.       walking = false;
  201.       speed = 0;
  202.       attacking = true;
  203.       ki -= ki_cost;
  204.       gotoAndStop("hit");
  205.       play();
  206.    }
  207. };
  208. if(!init)
  209. {
  210.    side = "L";
  211.    orig_scale = _xscale;
  212.    init = true;
  213. }
  214. slash1 = function()
  215. {
  216.    if(jumping || slashing)
  217.    {
  218.       return undefined;
  219.    }
  220.    slashing = true;
  221.    gotoAndStop("hit");
  222.    play();
  223. };
  224. right = function()
  225. {
  226.    turn("R");
  227. };
  228. left = function()
  229. {
  230.    turn("L");
  231. };
  232. turn = function(sideto)
  233. {
  234.    if(!sideto)
  235.    {
  236.       if(side == "L")
  237.       {
  238.          sideto = "R";
  239.       }
  240.       else
  241.       {
  242.          sideto = "L";
  243.       }
  244.    }
  245.    if(side != sideto)
  246.    {
  247.       if(!jumping)
  248.       {
  249.          turnTo = sideto;
  250.          walking = false;
  251.          jumping = false;
  252.          parrying = false;
  253.          if(sideto == "L")
  254.          {
  255.             _xscale = orig_scale;
  256.          }
  257.          else
  258.          {
  259.             _xscale = - orig_scale;
  260.          }
  261.          side = sideto;
  262.       }
  263.    }
  264.    else
  265.    {
  266.       turning = false;
  267.    }
  268. };
  269. playSound = function(ids)
  270. {
  271.    _root.sounds.playSound(ids);
  272. };
  273. stop();
  274.